<?php

	/*TIME FOR SOME POSTAPI SHIT HERE*/
	
	//all of this needs auth.post, so check it first
	if(!API_getAuth('post')){
		//see if they're trying to login, if so startAuth it
		if($_POST['jackedLogin']){
			$login = jackedLogin($_POST['username'], $_POST['password']);
			if($login === true){
				api_done(jackedSession_read("auth.post.username"));
			}else{
				api_error($login['reason'], "NO. JUST NO.");
			}
		}else{
			api_error('POST methods are protected. Login first.', 'BITCH, CAN\'T ADMIN IF YOU\'RE NOT ADMIN');
		}
	}else{
		//SWEET WE IS ADMIN
		switch($_POST['action']){
			case 'jackedLogin':
				api_done('Uh...you were already logged in. Stop trying to log in harder.');
				break;
				
			case 'getLengths':
				api_done(getLengths());
				break;
				
			case 'getSubmissions':
				api_done(getSubmissions($_POST['howMany']? $_POST['howMany'] : 0, $_POST['page']? $_POST['page'] : 0, true));
				break;
				
			case 'getSubmissionByID':
				api_done(getSubmissionByID($_POST['id']));
				break;
			
			case 'deleteSubmissionByID':
				api_done(deleteSubmissionByID($_POST['id']));
				break;
			
			case 'getSubmissionsLength':
				api_done(getSubmissionsLength());
				break;
			
			case 'getQueueLength':
				api_done(getQueueLength());
				break;
			
			case 'enqueueSubmission':
				if($_POST['id'] && $_POST['decision'] && $_POST['result'] && $_POST['tags']){
					api_done(enqueueSubmission($_POST['id'], $_POST['decision'], $_POST['result'], $_POST['tags']));
				}else{
					api_error('Not all fields provided.', 'You left something out, dumbass');
				}
				break;
			
			default:
				api_error("No API action was requested.", "If you want something, fucking ask for it.");
				break;
		}
	}
?>